import { request } from "@/services";

export function postUsersListDataAPI(queryInfo: any) {
  return request.post({
    url: "/users/list",
    data: queryInfo
  });
}

export function deleteUserByIdAPI(id: number) {
  return request.delete({
    url: `/users/${id}`
  })
}

export function addUserAPI(userInfo: any) {
  return request.post({
    url: "/users",
    data: userInfo
  })
}

export function getRoleList(pageInfo?: { offset: number, size: number }) {
  return request.post({
    url: '/role/list',
    data: pageInfo
  })
}

export function getDepartmentList(pageInfo?: { offset: number, size: number }) {
  return request.post({
    url: '/department/list',
    data: pageInfo
  })
}

export function getMenuList() {
  return request.post({
    url: '/menu/list'
  })
}

/**
 * 封装通用页面的增删改查接口
 */
export function postPageListData(pageName: string, queryInfo: any) {
  return request.post({
    url: `/${pageName}/list`,
    data: queryInfo,
    interceptors: {
      requestSuccessFn: (config) => {
        console.log("单个接口请求成功的回调")
        return config
      }
    }
  })
}

export function deletePageById(pageName: string, id: number) {
    return request.delete({
        url: `/${pageName}/${id}`
    })
}

export function newPageData(pageName: string, pageInfo: any) {
  return request.post({
    url: `/${pageName}`,
    data: pageInfo
  })
}

export function editPageData(pageName: string, id: number, pageInfo: any) {
  return request.patch({
    url: `/${pageName}/${id}`,
    data: pageInfo
  })
}
